/**
 * 评价
 * @author Qasim <15750783791@163.com>
 * @version 2016/11/3
 */
document.addEventListener('plusready' , ready , false);
var self = memberInfo = '' 
function ready(){
	self = plus.webview.currentWebview();
	memberInfo = plus.storage.getItem('memberInfo');
	memberInfo = $.parseJSON(memberInfo);
	
	//加载数据
	comments();
	
}


function comments(){
	$.ajax({
		type:"post", 
		url:apiRoot + "/Home/Comments/comments/",
		data:{
			uid : memberInfo.aid
		}, 
		async:false,
		dataType:'json', 
		beforeSend: function(){
			plus.nativeUI.showWaiting('加载中...');
		},
		complete:function(){   
			plus.nativeUI.closeWaiting(); 
		},
		success : function(data){ 
			if(data){
				$.each(data , function(k,v){
					var html  = '<div class="list-p list'+v.id+'" book-id="'+v.bookInfo.id+'" book-price="'+v.bookInfo.price+'"><ul class="mui-table-view">';
						html += '<li class="mui-table-view-cell mui-media"><a href="javascript:;">';
						html += '<img class="mui-media-object mui-pull-left" src="'+getImgUrl(v.bookInfo.litpic , '../public/img/default.png')+'">';
						html += '<div class="mui-media-body"><div><span>'+v.bookInfo.book_name+'</span>';
						html += '<div class="mui-pull-right text">'+v.content+'</div></div>'; 
						html += '<p class="m2"><span class="mui-h5">'+v.bookInfo.author+'</span>';
						html += '<span class="font10 mui-pull-right">'+v.addtime+'</span></p></div></a></li></ul></div>';
								
					$('.book_lists').append(html); 
					
					$('.list-p').unbind(); 
					//点击跳转
					$('.list-p').on('tap' , function(){
						bookDetails($(this).attr('book-id') , $(this).attr('book-price'));
					})
					
					//长按删除
					$('.list-p').on('longtap' , function(){
						__this = $(this);
						plus.nativeUI.confirm('温馨提示: 	确定要删除该评价吗？' , function(e){
							if(e.index == 0){
				 				$.ajax({
				 					type:"post",
				 					url:apiRoot + "/Home/Comments/delete/",
				 					data:{
				 						id : __this.attr('book-id'),
				 						uid : memberInfo.aid
				 					},
				 					beforeSend: function(){
										plus.nativeUI.showWaiting('加载中...');
									},
									complete:function(){   
										plus.nativeUI.closeWaiting(); 
									},
									success : function(data){
										if(data > 0){
											__this.remove();
											toast('已删除');
										}
									},
									error: function(e){
										errorPrompt(e)
									}
				 				});
				 			}
				 		} , '电子阅读' , ['确定' , '取消'])
					})
					
				})
			}else{
				toast('没有数据');
			}
		},
		error : function(e){
			errorPrompt(e)
		}
	})
}
